Skip to main content

Unit Testing

Smart contract unit tests are authored in Javascript.

In this tutorial, we provide two illustrations of unit testing using Hardhat and Truffle.

Unit testing in Hardhat

https://github.com/Torus-foundation/unittestexample-hardhat

Unit testing in Truffle

https://github.com/Torus-foundation/unittestexample-truffle

Each example repository encompasses the following:

  • contracts folder: This holds the smart contract files.
  • test folder: The unit test files are situated under the test folder.
  • README.md file: This contains guidelines for compiling, testing, deploying, and verifying the smart contracts.

In the aforementioned examples, unit tests are incorporated into a single Javascript file. However, you can include as many tests and files as your project necessitates.

In the illustrations, there are three categories of tests:

  • Verifying if a value aligns with what's expected
  • Checking if an event is initiated with the correct arguments
  • Checking if a revert has occured.